package ihm.util;

import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 * @author david.tamisier
 */
public class Util {

    private static ResourceBundle rb = ResourceBundle.getBundle("Bundle");

    /**
     *
     * @param cliendId
     * @param messageSummaryId
     * @param messageDetailId
     * @param context
     * @param severity
     * @param params
     */
    public static void addMessage(String cliendId, String messageSummaryId, String messageDetailId, FacesContext context,
            FacesMessage.Severity severity, Object... params) {

        String summary = rb.getString(messageSummaryId);
        String detail = rb.getString(messageDetailId);

        context.addMessage(cliendId, new FacesMessage(severity, summary, detail));
    }

    /**
     *
     * @param cliendId
     * @param messageSummaryId
     * @param messageDetailId
     * @param context
     * @param params
     */
    public static void addErrorMessage(String cliendId, String messageSummaryId, String messageDetailId,
            FacesContext context, Object... params) {
        addMessage(cliendId, messageSummaryId, messageDetailId, context,
                FacesMessage.SEVERITY_ERROR, params);
    }

    /**
     *
     * @param cliendId
     * @param messageId
     * @param context
     * @param params
     */
    public static void addErrorMessage(String cliendId, String messageId,
            FacesContext context, Object... params) {
        addMessage(cliendId, messageId, messageId, context,
                FacesMessage.SEVERITY_ERROR, params);
    }

    /**
     *
     * @param cliendId
     * @param messageSummaryId
     * @param messageDetailId
     * @param context
     * @param params
     */
    public static void addInfoMessage(String cliendId, String messageSummaryId, String messageDetailId,
            FacesContext context, Object... params) {
        addMessage(cliendId, messageSummaryId, messageDetailId, context,
                FacesMessage.SEVERITY_INFO, params);
    }

    /**
     *
     * @param cliendId
     * @param messageId
     * @param context
     * @param params
     */
    public static void addInfoMessage(String cliendId, String messageId,
            FacesContext context, Object... params) {
        addMessage(cliendId, messageId, messageId, context,
                FacesMessage.SEVERITY_INFO, params);
    }
}
